const https = require('https')
// 是后端像后端请求
const http = require('http')
const querystring = require("querystring")
const logger = require('../log')

const postData = querystring.stringify({
    name: "李四",
    age: 23,
    sex: 0
})
const server = http.createServer((req, res) => {

    const reqs = http.request({
        protocol: 'http:',
        hostname: 'localhost',
        method: 'post',
        port: '3000',
        path: '/data',
        headers: {
            "content-type": "application/x-www-form-urlencoded",
            "Content-Length": Buffer.byteLength(postData)
        }
    }, (result) => {
        let data = ''
        result.on('data', (chunk) => {
            data += chunk
        })
        result.on('end',()=>{
            console.log(data);
        })

    })
    reqs.write(postData)
    reqs.end()
    
    res.end()
})
server.listen('3000', () => {
    console.log('q');
})
